﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Maticsoft.DBUtility;
namespace BLL.ManageDBLNo
{
    public class ManageLast3Code
    {
        
        public static int SetLast3CodeSequenceAvailableOrNot(int seqLength,bool isAvailable)
        {

            List<string> list = GenerateCode.GenerateSequenceCode(seqLength, true);//生成正反序列

            return UpdateLast3Code(list,isAvailable);
        }

        public static int SetLast3CodRepeateAvailableOrNot(int repeateLength, bool isAvailable)
        {
            List<string> list = GenerateCode.GenerateRepeatCode(repeateLength);

            return UpdateLast3Code(list,isAvailable);
        }

        public static int UpdateLast3Code(List<string> list,bool isAvailable)
        {
            int affectCount = 0;
            string ar = string.Empty;
            if (isAvailable == true)
            {
                ar = "A";
            }
            else
            {
                ar = "R";
            }

            for (int i = 0; i < list.Count; i++)
            {
                string sqlstr = @"update b_last3code 
                                    set availablereserve = '" + ar + @"'
                                    where last3code like '%" + list[i] + "%'";

                int count = DbHelperOra.ExecuteSql(sqlstr);
                affectCount += count;
            }
            return affectCount;
        }

        public static DataSet GetAllLast3Code()
        {
            return DbHelperOra.Query("select * from b_last3code");
        }

        public static DataSet GetAllLast3CodeReserve()
        {
            return DbHelperOra.Query("select * from b_last3code where availablereserve = 'R'");
        }

        public static DataSet GetLast3Code(string strLike)
        {
            string sqlstr = "select * from b_last3code ";
            if(!strLike.Equals(""))
            {
                sqlstr = sqlstr+" where last3code like'%"+strLike+"%'";
            }
            return DbHelperOra.Query(sqlstr);
        }
    }
}
